package com.yanqu.road.dao.impl.player;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.player.InternalUserIpLocation;
import com.yanqu.road.entity.player.WechatRankBlackUserData;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class WechatRankBlackUserDaoImpl extends TempDao {

    /**
     * 获取微信排名黑名单用户数据
     * @param channelId
     * @return
     * @throws Exception
     */
    public Map<String, WechatRankBlackUserData> getWechatRankBlackUserData(long channelId) throws Exception {
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from t_s_wechat_rank_black_user where channelId = ?";
        Map<String, WechatRankBlackUserData> dataMap = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            call.setLong(1, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                WechatRankBlackUserData data = new WechatRankBlackUserData();
                data.setOpenId(rs.getString("openId"));
                data.setChannel(rs.getInt("channelId"));
                dataMap.put(data.getOpenId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }
}

